<template>
	<div>
		<el-dialog title="请输入您想添加的金币数" :visible.sync="dialogVisible" width="30%" :before-close="handleClose">
			<span>
				<el-input v-model="coin" /></span>
			<span slot="footer" class="dialog-footer">
				<el-button @click="dialogVisible = false">取 消</el-button>
				<el-button type="primary" @click="confirmaddCoin">确 定</el-button>
			</span>
		</el-dialog>
		<div class="search">
			<div class="content">
				<div class="part1">
					<div class="item">
						<span class="name">名字</span>
						<el-input v-model="detail.title" class="input margin-left" placeholder="名字" maxlength="20" @keyup.enter.native="search" />
					</div>
					<div class="searchItem">
						<el-button type="success" round class="search-btn" @click="getList">搜索</el-button>
						<el-button round class="reset-btn" style="margin-left:20px;" @click="reset">重置</el-button>
						<el-button round class="add" style="margin-left:20px;" @click="$router.push({path:'/member/add',query:{type:1}})">新增</el-button>
					</div>
				</div>
			</div>
		</div>
		<div class="table margin-top padding-bottom">
			<el-table ref="multipleTable" empty-text="暂无数据" :data="list" style="width: 100%" :row-style="{background: '#FCFDFF'}"
			 :header-cell-style="{background:'#46705D',color:'#ffffff'}" @select-all="handleSelectAll" @selection-change="handleSelectionChange">
				<el-table-column type="selection" width="55" />
				<el-table-column fixed type="index" label="序号" :show-overflow-tooltip="true" align="center" />
				<el-table-column label="账号" :show-overflow-tooltip="true" align="center">
					<template slot-scope="scope">
						<div>{{ scope.row.account }}</div>
					</template>
				</el-table-column>
				<el-table-column label="名字" :show-overflow-tooltip="true" align="center">
					<template slot-scope="scope">
						<div>{{ scope.row.name }}</div>
					</template>
				</el-table-column>
				<el-table-column label="手机号" :show-overflow-tooltip="true" align="center">
					<template slot-scope="scope">
						<div>{{ scope.row.phone }}</div>
					</template>
				</el-table-column>
				<el-table-column label="注册时间" :show-overflow-tooltip="true" align="center">
					<template slot-scope="scope">
						<div>{{ scope.row.createAt }}</div>
					</template>
				</el-table-column>
				<el-table-column label="认证时间" :show-overflow-tooltip="true" align="center">
					<template slot-scope="scope">
						<div>{{ scope.row.updateAt }}</div>
					</template>
				</el-table-column>
				<el-table-column label="头像" :show-overflow-tooltip="true" align="center">
					<template slot-scope="scope">
						<div class="bgGrey"><img :src="scope.row.headPortrait" alt=""></div>
					</template>
				</el-table-column>
				<el-table-column label="状态" :show-overflow-tooltip="true" align="center">
					<template slot-scope="scope">
						<div>
							{{ getStatus(scope.row.status) }}
						</div>
					</template>
				</el-table-column>
				<el-table-column fixed="right" label="操作" :show-overflow-tooltip="true" align="center" width="450">
					<template slot-scope="scope">
						<el-button type="text" size="small" @click="toSee(scope.row)">查看</el-button>
						<el-button type="text" size="small" @click="toEdit(scope.row)">编辑</el-button>
						<el-button type="text" size="small" @click="toLevel(scope.row.userId)">等级设置</el-button>
						<el-button type="text" size="small" @click="changeStatus(scope.row,1)">禁用</el-button>
						<el-button type="text" size="small" @click="changeStatus(scope.row,0)">启用</el-button>
						<el-button type="text" size="small" @click="addCoin(scope.row)">加金币</el-button>
						<el-button type="text" size="small" @click="toDel(scope.row.id)">删除</el-button>
					</template>
				</el-table-column>
			</el-table>
			<div class="pageContain margin-top">
				<div>
					<el-popover placement="right" trigger="hover" class="more">
						<div class="popover">
							<!--              <div class="item hand" @click="editStatusSingles(1)">启用</div>-->
							<!--              <div class="item hand" @click="editStatusSingles(0)">禁用</div>-->
							<div class="item hand" @click="toDels">删除</div>
						</div>
						<el-button slot="reference" class="moreDo">批量操作</el-button>
					</el-popover>
				</div>
				<div style="flex: 1;text-align: right;">共{{pagination.total}}条</div>
				<el-pagination :current-page="pagination.page" :page-size="pagination.pageSize" :background="true" layout="prev, pager, next"
				 :total="pagination.total" @current-change="handleCurrentChange" />
			</div>
		</div>
		<div tabindex="1" role="dialog" v-if="meng==true" aria-modal="true" aria-label="提示" class="el-message-box__wrapper" style="z-index: 2015;background-color: rgba(0,0,0,0.5);">
			<div class="el-message-box">
				<div class="el-message-box__header">
					<div class="el-message-box__title">
						<span>提示</span>
					</div>
					<button @click="out"  type="button" aria-label="Close" class="el-message-box__headerbtn"><i class="el-message-box__close el-icon-close"></i></button>
				</div>
				<div class="el-message-box__content">
					<div class="el-message-box__container">
						<div class="el-message-box__message">
							<p>请选择等级</p>
						</div>
					</div>
					<div class="el-message-box__input" style="">
						<div class="el-input">
							<select name="value" id="" v-model="secs" class="el-input__inner">
								<option value="1">青铜骑士</option>
								<option value="2">黄金骑士</option>
								<option value="3">铂金骑士</option>
							</select>
						</div>
						<div class="el-message-box__errormsg" style="visibility: hidden;"></div>
					</div>
				</div>
				<div class="el-message-box__btns">
					<button type="button" @click="out" class="el-button el-button--default el-button--small">
						<span>
							取消
						</span>
					</button>
					<button type="button" @click="oks" class="el-button el-button--default el-button--small el-button--primary ">
						<span>
							确定
						</span>
					</button>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
	import {
		agentAddIntegral,
		agentsUpdateStatus,
		agentList,
		agentDelete,
		agentUpdateTag
	} from '@/api/api'
	export default {
		data() {
			return {
				list: [],
				idse:0,
				meng:false,
				dialogVisible: false,
				currentId: '',
				coin: '',
				secs: 0,
				pagination: {
					pageSize: 10,
					page: 1,
					total: 0
				},
				detail: {
					postId: this.postId,
					showType: '',
					title: ''
				},
				statusOptions: [{
						value: null,
						label: '全部'
					},
					{
						value: 1,
						label: '正常'
					},
					{
						value: 0,
						label: '禁用'
					}
				],
				ids: []
			}
		},
		created() {
			this.getList()
		},
		methods: {
		oks(){
			agentUpdateTag({
				userId: this.idse,
				agentVideoLevel: this.secs
			}).then(data => {
				Is.tip('设置成功')
				this.getList()
				this.meng=false
			})
		},
		out(){
			this.meng=false;
		},
			handleClose(done) {
				this.$confirm('确认关闭？')
					.then(_ => {
						done()
					})
					.catch(_ => {})
			},
			confirmaddCoin() {
				let _this = this
				agentAddIntegral({
					id: this.currentId,
					integral: parseInt(this.coin)
				}).then(data => {
					Is.tip('添加成功')
					_this.dialogVisible = true
				})
			},
			// 添加金币
			addCoin(item) {
				this.currentId = item.id
				this.dialogVisible = true
			},
			changeStatus(item, type) {
				agentsUpdateStatus({
					id: item.userId,
					status: type
				}).then(data => {
					Is.tip('编辑成功')
					this.getList()
				})
			},
			getStatus(status) {
				let statusWord = ''
				switch (status) {
					case 0:
						statusWord = '启用'
						break
					case 1:
						statusWord = '禁用'
						break
					case 2:
						statusWord = '冻结'
						break
					case 3:
						statusWord = '待审核'
						break
				}
				return statusWord
			},
			toLevel(id) {

				this.idse=id;
				this.meng=true



			},
			toEdit(item) {
				this.$router.push({
					path: '/member/add',
					query: {
						id: item.id,
						type: 1
					}
				})
			},
			toSee(item) {
				this.$router.push({
					path: '/member/see',
					query: {
						id: item.id,
						type: 1
					}
				})
			},
			editStatusSingle(type, id) {
				if (type == 1) {
					// 启用
					updateHospitalStatus({
						ids: [id],
						status: 1
					}).then(data => {
						Is.tip('启用成功')
						this.getList()
					})
				}
			},
			editStatusSingles(type) {
				if (Is.empty(this.ids)) {
					Is.tip('未选择编辑项')
					return false
				}
				if (type == 1) {
					// 启用
					agentsUpdateStatus({
						ids: this.ids,
						status: 1
					}).then(data => {
						Is.tip('启用成功')
						this.getList()
					})
				}
				if (type == 0) {
					// 禁用
					agentsUpdateStatus({
						ids: this.ids,
						status: 0
					}).then(data => {
						Is.tip('禁用成功')
						this.getList()
					})
				}
			},
			reset() {
				this.detail = {
					postId: this.postId,
					showType: '',
					title: ''
				}
				this.pagination = {
					pageSize: 10,
					page: 1,
					total: 0
				}
				this.getList()
			},
			getList() {
				const params = {
					curPage: this.pagination.page,
					pageSize: this.pagination.pageSize,
					name: this.detail.title
				}
				agentList(params).then(({
					data
				}) => {
					this.list = data.records
					this.pagination.total = data.total
					// this.list = data
				})
			},
			handleSelectAll(selection) {
				this.ids = []
				if (selection.length > 0) {
					selection.forEach(item => {
						this.ids.push(item.id)
					})
				}
			},
			handleCurrentChange(val) {
				// 重置当前页码
				this.pagination.page = val
				this.getList()
			},
			handleSelectionChange(selection) {
				this.ids = []
				if (selection.length > 0) {
					selection.forEach(item => {
						this.ids.push(item.id)
					})
				}
			},
			// 多选删除
			toDels() {
				if (Is.empty(this.ids)) {
					Is.tip('未选择删除项')
					return false
				}
				this.$confirm('确认删除？', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					agentDelete(
						this.ids
					).then(data => {
						Is.tip('删除成功', 1500, 'success')
						if (this.list.length === this.ids.length && this.pagination.page > 1) {
							this.pagination.page--
						}
						this.getList()
					})
				})
			},
			// 单选删除
			toDel(id) {
				this.$confirm('确认删除？', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					agentDelete(
						[id]
					).then(data => {
						Is.tip('删除成功', 1500, 'success')
						if (this.list.length === 1 && this.pagination.page > 1) {
							this.pagination.page--
						}
						this.getList()
					})
				}).catch((e) => {

				})
			}
		}
	}
</script>

<style lang="scss" scoped>

</style>
